package com.lzxuni.modules.pccontrol.home.culture.member.controller;


import com.alibaba.fastjson.JSON;
import com.lzxuni.common.annotation.SysLog;
import com.lzxuni.common.constant.LogConstant;
import com.lzxuni.common.utils.R;
import com.lzxuni.common.utils.StringUtils;
import com.lzxuni.common.utils.UuidUtil;
import com.lzxuni.modules.common.controller.BaseController;
import com.lzxuni.modules.common.entity.PageData;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.common.entity.Tree;
import com.lzxuni.modules.pccontrol.home.culture.member.entity.CultureMember;
import com.lzxuni.modules.pccontrol.home.culture.member.service.CultureMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 文化管理-文艺团体表 前端控制器
 * </p>
 *
 * @author fcd
 * @since 2019-07-18
 */
@RestController
@RequestMapping("/tblHomeCultureMember")
public class CultureMemberController extends BaseController {

    @Autowired

    private CultureMemberService tblHomeCultureMemberService;

    @RequestMapping("/Index")
    @SysLog(categoryId = 2, module = "文化管理-文艺团体管理", operateType = "访问")
    public ModelAndView list(){
        ModelAndView mv = new ModelAndView("/pccontrol/home/culture/member/index");
        return mv;
    }

    @RequestMapping("/GetList")
    public Object GetList(String pagination, CultureMember tblHomeCultureMember) {
        tblHomeCultureMember.setIsdel("1");
        //1.Json转换成实体类
        PageParameter pageParameter = JSON.parseObject(pagination, PageParameter.class);
        //调用父类的一个方法，传进一个参数pageParameter进行查询操作将在业务层将结果直接封装进PageInfo中然后将PageInfo数据封装进pageData中，返回到页面中
        PageData pageData = getPageData(tblHomeCultureMemberService.queryPage(pageParameter, tblHomeCultureMember));
        return R.ok().put("data", pageData);
    }


    @RequestMapping("/GetTree")
    public Object GetTree(String communityid) {
        List<Tree> villageList = tblHomeCultureMemberService.getTree(communityid);
        return R.ok().put("data",villageList);
    }

    @RequestMapping("/getGroup")
    public Object getGroup() {
        List<Tree> companyList = tblHomeCultureMemberService.getGroup();
        return R.ok().put("data",companyList);
    }

    @RequestMapping("/Form")
    public ModelAndView Form() {
        ModelAndView mv = new ModelAndView("/pccontrol/home/culture/member/form");
        return mv;
    }


    @SysLog(categoryId = LogConstant.OPERATEID,module = "文化管理-文艺团体管理",operateType = LogConstant.INSERT)
    @RequestMapping("/SaveForm")
    public Object SaveForm(CultureMember tblHomeCultureMember, String keyValue, String isshow){
        if(StringUtils.isNotEmpty(keyValue) && "1".equals(isshow)){
            tblHomeCultureMember.setId(keyValue);
            tblHomeCultureMember.setIsshow(isshow);
            tblHomeCultureMemberService.updateById(tblHomeCultureMember);
            return R.ok("审核成功");
        }else if(StringUtils.isNotEmpty(keyValue) && "0".equals(isshow)){
            tblHomeCultureMember.setId(keyValue);
            tblHomeCultureMember.setIsshow(isshow);
            tblHomeCultureMemberService.updateById(tblHomeCultureMember);
            return R.ok("取消审核成功");
        }else if(StringUtils.isNotEmpty(keyValue) && "3".equals(isshow)){
            tblHomeCultureMember.setId(keyValue);
            tblHomeCultureMember.setIsdel("0");
            tblHomeCultureMemberService.updateById(tblHomeCultureMember);
            return R.ok("删除成功");
        }else if(StringUtils.isNotEmpty(keyValue)){
            tblHomeCultureMember.setId(keyValue);
            tblHomeCultureMemberService.updateById(tblHomeCultureMember);
            return R.ok("修改成功");
        }else{
            String ywId = UuidUtil.get32UUID();
            tblHomeCultureMember.setId(ywId);
            tblHomeCultureMember.setDate(new Date());
            tblHomeCultureMember.setIsdel("1");
            tblHomeCultureMemberService.SaveForm(tblHomeCultureMember);
            return R.ok("保存成功");
        }

    }

}

